﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity;

namespace GameSchool.Models
{
    class AchievementConfiguration : EntityTypeConfiguration<Achievement>
    {
        internal AchievementConfiguration()
        {
            //Achievement has one teacher, teacher has multiple achievementsS
            this.HasOptional(a => a.teacher)
                .WithMany(t => t.achievements)
                .HasForeignKey(a => a.teacherID);
        }
    }

    class LevelConfiguration : EntityTypeConfiguration<Level>
    {
        internal LevelConfiguration()
        {
            //Level has one course, course has multiple levels
            this.HasRequired(l => l.course)
                .WithMany(c => c.levels)
                .HasForeignKey(l => l.courseID);
        }
    }

    class AssignmentConfiguration : EntityTypeConfiguration<Assignment>
    {
        internal AssignmentConfiguration()
        {
            //Assignment has one level, level has multiple assignments
            this.HasRequired(a => a.level)
                .WithMany(l => l.assignments)
                .HasForeignKey(a => a.levelID);
        }
    }

    class QuestionConfiguration : EntityTypeConfiguration<Question>
    {
        internal QuestionConfiguration()
        {
            //Question has one exam, exam has multiple questions
            this.HasRequired(q => q.exam)
                .WithMany(e => e.questions)
                .HasForeignKey(q => q.examID);
        }
    }

    class CommentConfiguration : EntityTypeConfiguration<Comment>
    {
        //comment has one teacher, teacher has multiple comments
        internal CommentConfiguration()
        {
            this.HasOptional(c => c.teacher)
                .WithMany(t => t.comments)
                .HasForeignKey(c => c.teacherID);

            //comment has one student, student has multiple comments
            this.HasOptional(c => c.student)
                .WithMany(s => s.comments)
                .HasForeignKey(c => c.studentID);

            //comment has one specific lecture, a lecture has multiple comments
            this.HasOptional(c => c.lecture)
                .WithMany(l => l.comments)
                .HasForeignKey(c => c.lectureID);
        }
    }

    class LikeConfiguration : EntityTypeConfiguration<Like>
    {
        internal LikeConfiguration()
        {
            //Like has only one comment, comment has multiple likes
            this.HasOptional(l => l.comment)
                .WithMany(c => c.likes)
                .HasForeignKey(l => l.commentID);

            //Like has only one student, student has multiple likes
            this.HasOptional(l => l.student)
                .WithMany(s => s.likes)
                .HasForeignKey(l => l.studentID);
        }

    }

    class LectureConfiguration : EntityTypeConfiguration<Lecture>
    {
        internal LectureConfiguration()
        {
            //Lecture has one level, level has many lectures
            this.HasOptional(l => l.level)
                .WithMany(le => le.lectures)
                .HasForeignKey(l => l.levelID);
        }
    }


    class ExamConfiguration : EntityTypeConfiguration<Exam>
    {

        internal ExamConfiguration()
        {
            //Exam has one level, level has multiple exams
            this.HasOptional(e => e.level)
                .WithMany(le => le.exams)
                .HasForeignKey(e => e.levelID);
        }

    }

    class AnswerConfiguration : EntityTypeConfiguration<Answer>
    {
        internal AnswerConfiguration()
        {
            //answer has one question, question has many answers

            this.HasOptional(a => a.question)
                .WithMany(q => q.answers)
                .HasForeignKey(a => a.questionID);
        }
    }
}



